var exp = module.exports;
var dispatcher = require('./dispatcher');

exp.game = function(session, msg, app, cb) {
	var roomId = session.rid || session.get('rid');
	var servers = null;
	if (roomId < Def.COIN_ROOM_ID_MIN) {
		servers = app.get("gameServers");
	} else if (roomId < Def.MATCH_ROOM_ID_MIN) {
		servers = app.get("sceneServers");
	} else {
		servers = app.get("matchServers")
	}

	if(!servers || servers.length === 0) {
		cb(new Error('can not find game servers.'));
		return;
	}

	var res = dispatcher.dispatch(roomId, servers);

	cb(null, res.id);
};
